package myClient.sender;

import component.userInformation.ChatMsg;
import org.springframework.stereotype.Service;
import protobuf.Serialization.ChatMsgConverter;
import protobuf.protoClass.ProtoMsg;

@Service("ChatSender")
public class ChatSender extends BaseSender {

    public void sendChatMsg(String toUid, String content) {
        System.out.println("发送消息 startConnectServer");

        ChatMsg chatMsg = new ChatMsg(getUserAttribute());
        chatMsg.setMsgId(System.currentTimeMillis());
        chatMsg.setTo(toUid);
        chatMsg.setMsgType(ChatMsg.MessageType.TEXT);
        chatMsg.setContent(content);
        ProtoMsg.Message message = ChatMsgConverter.build(chatMsg, getSession());

        super.sendMsg(message);
    }

    @Override
    protected void sendSucceed(ProtoMsg.Message message) {
        System.out.println("发送成功:" + message.getMessageRequest().getContent());
    }

    @Override
    protected void sendFailed(ProtoMsg.Message message) {
        System.out.println("发送失败:" + message.getMessageRequest().getContent());
    }

}
